home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / itrns211.zip / SRC / ITRANS.C < prev    next >
C/C++ Source or Header  |  1991-10-14  |  14KB  |  469 lines

  1. /*
  2.  *========================================================================== 
  3.  * Copyright 1991 Avinash Chopde, All Rights Reserved.
  4.  *
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of Avinash Chopde not be used in
  10.  * advertising or publicity pertaining to distribution of the software
  11.  * without specific, written prior permission.
  12.  * Avinash Chopde makes no representations about the suitability of this
  13.  * software for any purpose.
  14.  * It is provided "as is" without express or implied warranty.
  15.  *
  16.  * AVINASH CHOPDE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  18.  * IN NO EVENT SHALL AVINASH CHOPDE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  20.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  21.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22.  * OF THIS SOFTWARE.
  23.  *
  24.  * Author:  Avinash Chopde, 1991
  25.  *
  26.  */
  27.  
  28. static char S_RCSID[] = "$Header: e:/itrans/src/rcs/itrans.c 1.9 91/10/14 20:18:06 avinash Exp $";
  29.  
  30. #include "itrans.h"
  31. #include "ifm.h"
  32.  
  33. static char S_copyright[] = "\
  34. %%\n\
  35. %% ----------------------------------------------------------------\n\
  36. %% Output from:\n\
  37. %% itrans %s, Copyright 1991 Avinash Chopde, All Rights Reserved.\n\
  38. %% ----------------------------------------------------------------\n\
  39. %%\n\
  40. ";
  41.  
  42. /* =================================================================== */
  43. #ifdef TCC
  44. /* Under Turbo-C++, declare the stacklen to be larger */
  45. extern unsigned _stklen = 7000U;
  46. #endif
  47. /* =================================================================== */
  48.  
  49. int G_verbose;
  50.  
  51. int G_currfontsize;
  52. int G_psout; /* if TRUE produce PostScript output, else TeX output */
  53.  
  54. static allfonts_t    S_allfonts;
  55. static lang_t        S_langs[LANGS_MAX];
  56.  
  57. font_t*            G_current_font=NULL; /*GLOBAL*/
  58.  
  59.  
  60. static void S_usage(FILE*);
  61.  
  62. /* =================================================================== */
  63. void cc_toany(letter_t dlet, font_t* mfontptr, char* comm, int* wid)
  64. {
  65.     int i, x, y;
  66.     static comp_unit_t    cus[100]; /* static just to over the PC's 
  67.         * stack size limits...!
  68.         */
  69.  
  70.     i = make_letter(mfontptr, dlet, cus, 100, &x, &y, wid);
  71.  
  72.     if (i > 0) {
  73.  
  74.     if (G_psout) cus_to_ps(cus, G_currfontsize, comm);
  75.     else cus_to_tex(cus, G_currfontsize, comm);
  76.  
  77.     }
  78.  
  79. } /* cc_toany() */
  80.  
  81. /* =================================================================== */
  82.  
  83. process_letter(letter_t in)
  84. {
  85.     static char comm[CONVWORD_LEN];
  86.     /* must be large enough to store one word -
  87.      * which in TeX can get very large..what with raise boxes, \char defs etc
  88.      * made it static since it is currently 8K bytes, and on the PC stack
  89.      * space is at a premium...
  90.      */
  91.  
  92.     int c1, c2, v, wid;
  93.     /* Check for output validity */
  94.     if (G_psout && G_current_font->prop == TEX_FONT) {
  95.     fprintf(stderr, "Font %s is for TeX output only - cannot do PostScript out\n", G_current_font->fname);
  96.  
  97.     /***** EXITS HERE *****/
  98.     exit(1);
  99.     /* return FALSE; */
  100.     }
  101.  
  102.     /*
  103.     fprintf(stderr, ":offset is %d in.v %d, in.c1 %d, in.c2 %d\n", OFFSET_TOK,
  104.                 in.v, in.c1, in.c2);
  105.     */
  106.  
  107.     if (in.v < OFFSET_TOK && in.v != HALF_FORM && in.v != IMPLICIT_FORM) {
  108.         fprintf(stderr,"illegal vowel val (c[0] is %d) - will use 'a' form\n", in.cons[0]);
  109.     }
  110.  
  111.  
  112.     switch(in.type) {
  113.     case VOWEL_TYPE:
  114.     v = _I_(in.v);
  115. #ifdef DEBUG
  116. fprintf(stderr, "process_letter: vowel %d\n", v);
  117. #endif /*DEBUG*/
  118.     cc_toany(in, G_current_font, comm, &wid);
  119.  
  120.     break;
  121.     case SPECIAL_TYPE:
  122.     c1 = _I_(in.cons[0]);
  123.     in.v = IMPLICIT_FORM; /* all specials printed in implicit form */
  124.  
  125. #ifdef DEBUG
  126. fprintf(stderr, "process_letter: special %d\n", c1);
  127. #endif /*DEBUG*/
  128.     
  129.     cc_toany(in, G_current_font, comm, &wid);
  130.  
  131.     break;
  132.     case CONSONANT_SINGLE_TYPE:
  133.     c1 = _I_(in.cons[0]);
  134.     v = _I_(in.v);
  135. #ifdef DEBUG
  136. fprintf(stderr, "process_letter: cons single %d vowel %d\n", c1, v);
  137. #endif /*DEBUG*/
  138.     
  139.     cc_toany(in, G_current_font, comm, &wid);
  140.  
  141.     break;
  142.  
  143.     case CONSONANT_DOUBLE_TYPE:
  144.     c1 = _I_(in.cons[0]);
  145.     c2 = _I_(in.cons[1]);
  146.     v = _I_(in.v);
  147.  
  148. #ifdef DEBUG
  149. fprintf(stderr, "process_letter: cons double %d %d vowel %d\n", c1, c2, v);
  150. #endif /*DEBUG*/
  151.     cc_toany(in, G_current_font, comm, &wid);
  152.  
  153.     break;
  154.  
  155.     case CONSONANT_MANY_TYPE:
  156.     c1 = _I_(in.cons[0]);
  157.     c2 = _I_(in.cons[1]);
  158.     v = _I_(in.v);
  159.  
  160. #ifdef DEBUG
  161. fprintf(stderr, "process_letter: cons many %d %d vowel %d\n", c1, c2, v);
  162. #endif /*DEBUG*/
  163.     cc_toany(in, G_current_font, comm, &wid);
  164.  
  165.     break;
  166.     }
  167.  
  168.     fputs(comm, stdout);
  169.  
  170.     if (G_psout) printf("\n");
  171.  
  172.     return TRUE;
  173. }
  174.  
  175. /* =================================================================== */
  176. int main(int argc, char *argv[])
  177. {
  178.     static char ifmfname[NAMELEN];
  179.     static char ifmcmd[NAMELEN];
  180.         /* static just to overcome the PC's stack size limitations */
  181.  
  182.     extern int yydebug;
  183.     int ch;
  184.     int psout;
  185.     extern char * optarg;
  186.     
  187. #ifdef sgi
  188.     mallopt(M_DEBUG, TRUE);
  189. #endif
  190.  
  191.     for (ch = 0; ch < FONTS_MAX; ch++) S_allfonts[ch] = NULL;
  192.  
  193.     ifmfname[0] = '\0';
  194.     G_currfontsize = 30;
  195.     G_verbose = 0;
  196.     psout = FALSE; /* by default, produce TeX output */
  197.  
  198.     /* --- Collect Args */
  199.     strcpy(ifmfname, DEVN_IFM_FILE);
  200.  
  201.     while ((ch = getopt(argc, argv, "hHPI:f:o:i:v")) != EOF) {
  202.     switch (ch) {
  203.     case 'h':
  204.     case 'H':
  205.        S_usage(stderr);
  206.        exit(0);
  207.        break;
  208.     case 'v':
  209.        G_verbose++;
  210.        break;
  211.     case 'P':
  212.        psout = TRUE;
  213.        break;
  214.     case 'I':
  215.        strcpy(ifmfname, optarg);
  216.        break;
  217.     case 'f':
  218.        sscanf(optarg, "%d", &G_currfontsize);
  219.        break;
  220.     case 'i':
  221.        if (!freopen(optarg, "r", stdin)) {
  222.            fprintf(stderr,"Error: Could not open %s for reading\n", optarg);
  223.            exit(1);
  224.        }
  225.        break;
  226.     case 'o':
  227.        if (!freopen(optarg, "w", stdout)) {
  228.            fprintf(stderr,"Error: Could not open %s for writing\n", optarg);
  229.            exit(1);
  230.        }
  231.        break;
  232.     default:
  233.        S_usage(stderr);
  234.        break;
  235.     } /* switch */
  236.     }
  237.     
  238.     G_psout = psout;
  239.  
  240.     for (ch = 0; ch < FONTS_MAX; ch++) {
  241.     S_allfonts[ch] = NULL;
  242.     }
  243.     init_langs(S_langs, LANGS_MAX);
  244.  
  245.     /* construct a line with a ifm command, so that
  246.      * the find_load_ifm function in lang.c can handle the loading...
  247.      */
  248.     sprintf(ifmcmd, "\\indianifm=%s", ifmfname);
  249.  
  250.     /* load in the default ifm file... */
  251.  
  252.     if (!find_load_ifm(&S_langs[0], S_allfonts, ifmcmd)) {
  253.      fprintf(stderr, "Warning: could not load default IFM %s (hope you don't need it..ERROR otherwise..)\n", ifmfname);
  254.     }
  255.  
  256.     G_current_font = S_langs[0].curr_font; /* default font */
  257.  
  258.     /* dump_font(S_allfonts[0], stderr); */
  259.  
  260.     yydebug = 0;
  261.     if (psout) {
  262.     printf("%%!PS\n%% *** Need files devnac.ps and itrans.pro before this line..\n");
  263.     fprintf(stderr, "** itrans, version %s (PostScript Interface)\n", ITRANS_VER);
  264.     } else {
  265.     fprintf(stderr, "** itrans, version %s (TeX Interface)\n", ITRANS_VER);
  266.     }
  267.  
  268.     printf(S_copyright, ITRANS_VER);
  269.  
  270.     if (psout) {
  271.     outps_start(G_currfontsize);
  272.     printf("/DevnacPlain findfont %s scalefont setfont\n", EMSIZE);
  273.     printf("/BASEFONTNAME /DevnacPlain def\n");
  274.     } else {
  275.     outtex_start();
  276.     }
  277.  
  278.     yyparse();
  279.  
  280.     if (psout) outps_end();
  281.     else outtex_end();
  282.  
  283.     return 0;
  284. }
  285. /* =================================================================== */
  286. process_newline()
  287. {
  288.     if (G_psout) printf("%%\nnewline\n");
  289.     else printf("\n");
  290.     return TRUE;
  291. }
  292. /* =================================================================== */
  293. process_space()
  294. {
  295.     if (G_psout) printf("( ) show ");
  296.     else printf(" ");
  297.     return TRUE;
  298. }
  299. /* ==============================================